Skip to content

Conversation

@JOE1994
Copy link
Contributor

@JOE1994 JOE1994 commented Jun 10, 2020

Since 'Vec::new()' is already a const function,
there is no difference in generated MIR/ASM whether
AsciiString::new() is marked const or not.
I saw issue #56 is waiting to mark this function as 'const',
and this PR simply marks 'AsciiString::new()' as a const fn.

cargo test successfully passed all tests in my local environment.

Thank you for reviewing this PR 😸

p.s.
I compared the generated MIR and ASM from https://play.rust-lang.org with/without const.

// Removing 'const' specifier does not change output of generated MIR & ASM :)
pub const fn new() -> Vec<i64> {
    Vec::new()
}

/* ASM OUTPUT
playground::new:
	movq	%rdi, %rax
	movq	$8, (%rdi)
	xorps	%xmm0, %xmm0
	movups	%xmm0, 8(%rdi)
	retq
*/

/* MIR OUTPUT
// WARNING: This output format is intended for human consumers only
// and is subject to change without notice. Knock yourself out.
fn new() -> std::vec::Vec<i64> {
    let mut _0: std::vec::Vec<i64>;      // return place in scope 0 at src/lib.rs:1:17: 1:25

    bb0: {
        _0 = const std::vec::Vec::<i64>::new() -> bb1; // bb0[0]: scope 0 at src/lib.rs:2:5: 2:15
                                         // ty::Const
                                         // + ty: fn() -> std::vec::Vec<i64> {std::vec::Vec::<i64>::new}
                                         // + val: Value(Scalar(<ZST>))
                                         // mir::Constant
                                         // + span: src/lib.rs:2:5: 2:13
                                         // + user_ty: UserType(0)
                                         // + literal: Const { ty: fn() -> std::vec::Vec<i64> {std::vec::Vec::<i64>::new}, val: Value(Scalar(<ZST>)) }
    }

    bb1: {
        return;                          // bb1[0]: scope 0 at src/lib.rs:3:2: 3:2
    }
}
*/

Since 'Vec::new()' is already a const function,
there is no difference in generated MIR/ASM whether
'AsciiString::new()' is marked 'const' or not.
I saw issue #56 is waiting to mark this function as 'const',
and so this PR simply marks 'AsciiString::new()' as a const fn.

Thanks for reviewing this PR :)
@tormol
Copy link
Collaborator

tormol commented Jun 10, 2020

Thanks, you probably also need to update minimum rust version in documentation and .travis.yml.

@tomprogrammer it looks like travis isn't working?

@pheki
Copy link

pheki commented Sep 11, 2020

As an aside, it looks like travis is working but for some reason its not showing in the PR.

It failed on 1.33, since Vec::new as const wasn't stable yet.

@tomprogrammer tomprogrammer merged commit 5c4a072 into tomprogrammer:master Oct 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants